// pages/register/register.js
Page({
  data: {

  },
  onLoad: function (options) {
  },
  formSubmit(e){
    let userObj = e.detail.value
    let {loginName,loginPassword,confirmPassword} = userObj
    if(!loginName||!loginPassword||!confirmPassword){
      wx.showToast({
        title: '数据不能为空',
      })
      return false
    }
      if(loginPassword !==confirmPassword){
        wx.showToast({
          title: '密码不一致',
        })
        return false
      }
      this.insert(userObj),
      this.tologin()
  },
  insert(userObj){
    let {list,classList} = this.data
    let {loginName,loginPassword}=userObj
    //获取数据库引用
    const db = wx.cloud.database();
    db.collection('user').add({
      data:{
        username: loginName,
        pwd: loginPassword
      },
    }).then(res=>{
      console.log(res)
    })
  },
  tologin(){
    wx.navigateTo({
      url: '../login/login',
    })
  },

})